package com.crusinnovation.unitTest.formatter;

import static org.junit.Assert.*;

import java.util.GregorianCalendar;

import org.junit.Before;
import org.junit.Test;

import com.cyrusinnovation.test.formatter.CommaRecordFormatter;
import com.cyrusinnovation.test.formatter.PersonRecordFormatter;
import com.cyrusinnovation.test.record.Gender;
import com.cyrusinnovation.test.record.PersonRecord;

public class CommaRecordFormatterTest {

	String recordString1 = "LastName, FirstName, Male, FavoriteColor, 11/1/1997";

	String recordString2 = "LastName, , , FavoriteColor";

	String recordString3 = "";

	PersonRecord record1 = new PersonRecord();

	PersonRecord record2 = new PersonRecord();

	PersonRecord record3 = new PersonRecord();

	PersonRecordFormatter formatter = new CommaRecordFormatter();

	@Before
	public void setUp() throws Exception {
		record1.setLastName("LastName");
		record1.setFirstName("FirstName");
		record1.setGender(Gender.MALE);
		record1.setFavoriteColor("FavoriteColor");
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.set(1997, 10, 1);
		record1.setDateOfBirth(calendar.getTime());

		record2.setLastName("LastName");
		record2.setFavoriteColor("FavoriteColor");
	}

	@Test
	public void testPersonRecordToString() {
		String str = recordString1.replaceAll(" ", "");
		assertEquals(formatter.PersonRecordToString(record1), 0, str
				.compareToIgnoreCase(formatter.PersonRecordToString(record1)));
		str = "LastName,,,FavoriteColor,";
		assertEquals(formatter.PersonRecordToString(record2), 0, str
				.compareToIgnoreCase(formatter.PersonRecordToString(record2)));
		str = ",,,,";
		assertEquals(formatter.PersonRecordToString(record3), 0, str
				.compareToIgnoreCase(formatter.PersonRecordToString(record3)));
	}

	@Test
	public void testStringToPersonRecord() {
		PersonRecord record = formatter.StringToPersonRecord(recordString1);
		assertEquals(record.toString(), record, record1);
		record = formatter.StringToPersonRecord(recordString2);
		assertEquals(record.toString(), record, record2);
		record = formatter.StringToPersonRecord(recordString3);
		assertEquals(record.toString(), record, record3);
	}

	
}
